const formatVoteState = (comment) => {
  if (comment.has_vote) {
    return {
      like: comment.has_vote.like,
      dislike: comment.has_vote.dis_like,
    };
  }
  return {};
};

const formatVoteCount = comment => ({
  like: comment.votes.like_size,
  dislike: comment.votes.dis_like_size,
});

export const formatComment = comment => ({
  id: comment.id,
  floor: comment.floor, // 第几楼
  content: comment.content,
  subsCount: comment.children_count, // 有层楼中楼

  authorId: comment.user.id,
  authorNickname: comment.user.nickname,
  authorAvatar: comment.user.avatar,

  author: comment.user ? {
    id: comment.user.id,
    nickname: comment.user.nickname,
    avatar: comment.user.avatar,
  } : {},

  parentId: comment.parent_id,
  receiver: comment.receiver, // id nickname avatar

  voteState: formatVoteState(comment),
  voteCount: formatVoteCount(comment),

  created_at: comment.created_at,
  updated_at: comment.updated_at,
});

export const formatComments = comments => comments.map(comment => formatComment(comment));
